/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ensisa.sunspot.actor;

import java.io.Serializable;
import java.util.Vector;

import fr.ensisa.sunspot.IKernel;
import fr.ensisa.sunspot.event.IEvent;

/**
 *
 * @author michel
 */
public abstract class AbstractActor implements IActor, Serializable {
	private static final long serialVersionUID = -4814114345051005358L;
	
	private IKernel kernel;
    private boolean activated;
    private int kind;
    private Template template;
    private IEvent generatedEvent = null;
    private Vector<IEvent> generatedEvents = null;

    public AbstractActor(int kind) {
        this.kind = kind;
        this.activated = true;
        this.template = null;
    }

    protected IKernel getKernel() {
        return kernel;
    }

    public void setKernel(IKernel kernel) {
        this.kernel = kernel;
    }

    public boolean isActivated () {
        return activated;
    }

    public void setActivated (boolean activated) {
        if (getKind () != IActor.KIND_SETUP)
            this.activated = activated;
    }

    public int getKind() {
        return kind;
    }

    public IActor setKind(int kind) {
        this.kind = kind;
        return this;
    }

    public IEvent getGeneratedEvent() {
        return generatedEvent;
    }

    protected void setGeneratedEvent(IEvent event) {
        generatedEvent = event;
    }

    public Vector<IEvent> getGeneratedEvents() {
        return generatedEvents;
    }

    protected void setGeneratedEvents(Vector<IEvent> events) {
        generatedEvents = events;
    }

    protected void setTemplate(Template template) {
        this.template = template;
    }
    
    protected void setTemplate(int major, int minor, int state) {
    	this.template = new Template(major, minor, state);
    }

    public boolean canProcess(IEvent event) {
        if (template == null) return true;
        if (event == null) return true;
        return template.accept (event);
    }

}
